import ErrorBoundary from '@/components/ErrorBoundary';
import BossLayout from '@/layouts/BossLayout';
import FormulaHome from '@/pages/boss/SafeIndex/Formula';
import { UploadOutlined, UserOutlined, VideoCameraOutlined } from '@ant-design/icons';
import { Spin } from 'antd';
import React, { lazy, Suspense } from 'react';
import type { NonIndexRouteObject } from 'react-router-dom';
import { createBrowserRouter, Outlet } from 'react-router-dom';

export interface bossRouteObject extends Omit<NonIndexRouteObject, 'children'> {
  key: string;
  label?: string;
  icon?: React.ReactNode;
  hidden?: boolean;
  children?: bossRouteObject[];
}

function lazyLoadFn(LazyComponent: ReturnType<typeof lazy>) {
  return (
    <Suspense
      fallback={
        <div>
          <Spin spinning={true}>组件加载中...</Spin>
        </div>
      }
    >
      <LazyComponent />
    </Suspense>
  );
}

const bossRouterChildren: bossRouteObject[] = [
  {
    path: 'resourceLibrary',
    key: 'resourceLibrary',
    label: '资源库',
    icon: <VideoCameraOutlined />,
    errorElement: <ErrorBoundary />,
    element: <Outlet />,
    children: [
      {
        path: 'courseWare/:activeTab?',
        key: 'courseWare',
        label: '课件',
        icon: <UploadOutlined />,
        element: lazyLoadFn(
          lazy(() => import(/* webpackChunkName: "resourceLibrary-courseware" */ '@/pages/boss/CourseWare')),
        ),
      },
      {
        path: 'addVideoCourseWare',
        key: 'addVideoCourseWare',
        label: '添加视频课件',
        hidden: true,
        element: lazyLoadFn(
          lazy(
            () =>
              import(/* webpackChunkName: "resourceLibrary-addVideoCourseWare" */ '@/pages/boss/AddVideoCourseWare'),
          ),
        ),
      },
      {
        path: 'addGraphicCourseWare',
        key: 'addGraphicCourseWare',
        label: '添加图文课件',
        hidden: true,
        element: lazyLoadFn(
          lazy(
            () =>
              import(
                /* webpackChunkName: "resourceLibrary-addGraphicCourseWare" */ '@/pages/boss/AddGraphicCourseWare'
              ),
          ),
        ),
      },
      {
        path: 'addPdfCourseWare',
        key: 'addPdfCourseWare',
        label: '添加pdf课件',
        hidden: true,
        element: lazyLoadFn(
          lazy(
            () => import(/* webpackChunkName: "resourceLibrary-addPdfCourseWare" */ '@/pages/boss/AddPdfCourseWare'),
          ),
        ),
      },
      {
        path: 'examination/:activeTab?',
        key: 'examination',
        label: '考题',
        icon: <UploadOutlined />,
        element: lazyLoadFn(
          lazy(() => import(/* webpackChunkName: "resourceLibrary-examination" */ '@/pages/boss/Examination')),
        ),
      },

      {
        path: 'addMChoiceQue',
        key: 'addMChoiceQue',
        label: '添加多选题',
        hidden: true,
        element: lazyLoadFn(
          lazy(() => import(/* webpackChunkName: "resourceLibrary-addMChoiceQue" */ '@/pages/boss/AddMChoiceQue')),
        ),
      },
      {
        path: 'addSChoiceQue',
        key: 'addSChoiceQue',
        label: '添加单选题',
        hidden: true,
        element: lazyLoadFn(
          lazy(() => import(/* webpackChunkName: "resourceLibrary-addSChoiceQue" */ '@/pages/boss/AddSChoiceQue')),
        ),
      },
      {
        path: 'addJudgeQue',
        key: 'addJudgeQue',
        label: '添加判断题',
        hidden: true,
        element: lazyLoadFn(
          lazy(() => import(/* webpackChunkName: "resourceLibrary-addJudgeQue" */ '@/pages/boss/AddJudgeQue')),
        ),
      },

      {
        path: 'testPaper',
        key: 'testPaper',
        label: '试卷',
        icon: <UserOutlined />,
        element: lazyLoadFn(
          lazy(() => import(/* webpackChunkName: "resourceLibrary-testPaper" */ '@/pages/boss/TestPaper')),
        ),
      },
      {
        path: 'addTestPaper',
        key: 'addTestPaper',
        label: '添加试卷',
        hidden: true,
        icon: <UserOutlined />,
        element: lazyLoadFn(
          lazy(() => import(/* webpackChunkName: "resourceLibrary-addTestPaper" */ '@/pages/boss/AddTestPaper')),
        ),
      },
    ],
  },
  {
    path: 'waitlisting',
    key: 'waitlisting',
    label: '待上架',
    icon: <VideoCameraOutlined />,
    element: <Outlet />,
    children: [
      {
        label: '课件包',
        path: 'package',
        key: 'package',
        icon: <UploadOutlined />,
        element: lazyLoadFn(
          lazy(() => import(/* webpackChunkName: "Listing-Package-Wait" */ '@/pages/boss/Listing/Package/Wait')),
        ),
      },
      {
        label: '计划模版',
        path: 'plantemp',
        key: 'plantemp',
        element: lazyLoadFn(
          lazy(() => import(/* webpackChunkName: "Listing-Package-Wait" */ '@/pages/boss/Listing/Plantemp/Wait')),
        ),
      },
      {
        label: '课程',
        path: 'kecheng',
        key: 'kecheng',
        element: lazyLoadFn(
          lazy(() => import(/* webpackChunkName: "Listing-Package-Wait" */ '@/pages/boss/Listing/Course/Wait')),
        ),
      },
      {
        label: '试卷',
        path: 'shelfPaper',
        key: 'shelfPaper',
        element: lazyLoadFn(
          lazy(() => import(/* webpackChunkName: "Listing-Package-Wait" */ '@/pages/boss/Listing/Paper/Wait')),
        ),
      },
    ],
  },
  {
    path: 'readylisting',
    key: 'readylisting',
    label: '已上架',
    icon: <VideoCameraOutlined />,
    element: <Outlet />,
    children: [
      {
        label: '课件包',
        path: 'package1',
        key: 'package1',
        element: lazyLoadFn(
          lazy(() => import(/* webpackChunkName: "Listing-Package-Wait" */ '@/pages/boss/Listing/Package/Ready')),
        ),
      },
      {
        label: '计划模版',
        path: 'plantemp1',
        key: 'plantemp1',
        element: lazyLoadFn(
          lazy(() => import(/* webpackChunkName: "Listing-Package-Wait" */ '@/pages/boss/Listing/Plantemp/Ready')),
        ),
      },
      {
        label: '课程',
        path: 'kecheng1',
        key: 'kecheng1',
        element: lazyLoadFn(
          lazy(() => import(/* webpackChunkName: "Listing-Package-Wait" */ '@/pages/boss/Listing/Course/Ready')),
        ),
      },
      {
        label: '试卷',
        path: 'shelfPaper1',
        key: 'shelfPaper1',
        element: lazyLoadFn(
          lazy(() => import(/* webpackChunkName: "Listing-Package-Wait" */ '@/pages/boss/Listing/Paper/Ready')),
        ),
      },
    ],
  },
  {
    path: 'safeIndex',
    key: 'safeIndex',
    label: '安全指数',
    icon: <VideoCameraOutlined />,
    element: <Outlet />,
    children: [
      {
        path: 'formula',
        key: 'formula',
        label: '计算公式',
        element: <FormulaHome />,
      },
      {
        path: 'setGrade',
        key: 'setGrade',
        label: '等级设置',
        element: <Outlet />,
        children: [
          {
            path: 'entSetGrade',
            key: 'entSetGrade',
            label: '企业安全指数等级设置',
            element: lazyLoadFn(
              lazy(() => import(/* webpackChunkName: "SafeIndex-EntSetGrade" */ '@/pages/boss/SafeIndex/EntSetGrade')),
            ),
          },
          {
            path: 'driverSetGrade',
            key: 'driverSetGrade',
            label: '司机安全指数等级设置',
            element: lazyLoadFn(
              lazy(
                () =>
                  import(/* webpackChunkName: "SafeIndex-DriverSetGrade" */ '@/pages/boss/SafeIndex/DriverSetGrade'),
              ),
            ),
          },
        ],
      },
      {
        path: 'impactFactor',
        key: 'impactFactor',
        label: '安全指数影响因子',
        element: <Outlet />,
        children: [
          {
            path: 'aboutCar',
            key: 'aboutCar',
            label: '车辆相关',
            element: lazyLoadFn(
              lazy(
                () => import(/* webpackChunkName: "resourceLibrary-courseware" */ '@/pages/boss/SafeIndex/AboutCar'),
              ),
            ),
          },
          {
            path: 'aboutDriver',
            key: 'aboutDriver',
            label: '司机相关',
            element: lazyLoadFn(
              lazy(
                () => import(/* webpackChunkName: "resourceLibrary-courseware" */ '@/pages/boss/SafeIndex/aboutDriver'),
              ),
            ),
          },
          {
            path: 'driverDoing',
            key: 'driverDoing',
            label: '驾驶行为',
            element: lazyLoadFn(
              lazy(
                () => import(/* webpackChunkName: "resourceLibrary-courseware" */ '@/pages/boss/SafeIndex/driverDoing'),
              ),
            ),
          },
        ],
      },
      {
        path: 'safeIndexStatistics',
        key: 'safeIndexStatistics',
        label: '安全指数统计',
        element: <Outlet />,
        children: [
          {
            path: 'carIndex',
            key: 'carIndex',
            label: '车辆安全指数',
            element: lazyLoadFn(
              lazy(
                () =>
                  import(/* webpackChunkName: "safeIndexStatistics-carIndex" */ '@/pages/boss/SafeIndex/SafeCarList'),
              ),
            ),
          },
          {
            path: 'carIndexInfo',
            key: 'carIndexInfo',
            hidden: true,
            label: '单车安全指数分析和详情',
            element: lazyLoadFn(
              lazy(
                () =>
                  import(
                    /* webpackChunkName: "safeIndexStatistics-driverIndex" */ '@/pages/boss/SafeIndex/SafeCarIndexInfo'
                  ),
              ),
            ),
          },
          {
            path: 'driverIndex',
            key: 'driverIndex',
            label: '司机安全指数',
            element: lazyLoadFn(
              lazy(
                () =>
                  import(
                    /* webpackChunkName: "safeIndexStatistics-driverIndex" */ '@/pages/boss/SafeIndex/SafeDriverList'
                  ),
              ),
            ),
          },
          {
            path: 'driverIndexInfo',
            key: 'driverIndexInfo',
            hidden: true,
            label: '司机安全指数分析和详情',
            element: lazyLoadFn(
              lazy(
                () =>
                  import(
                    /* webpackChunkName: "safeIndexStatistics-driverIndex" */ '@/pages/boss/SafeIndex/SafeDriverIndexInfo'
                  ),
              ),
            ),
          },
          {
            path: 'safeDriverComparison',
            key: 'safeDriverComparison',
            hidden: true,
            label: '司机得分对比',
            element: lazyLoadFn(
              lazy(
                () =>
                  import(
                    /* webpackChunkName: "safeDriverComparison-driverIndex" */ '@/pages/boss/SafeIndex/SafeDriverComparison'
                  ),
              ),
            ),
          },
          {
            path: 'entIndex',
            key: 'entIndex',
            label: '企业安全指数',
            element: lazyLoadFn(
              lazy(
                () =>
                  import(/* webpackChunkName: "safeIndexStatistics-entIndex" */ '@/pages/boss/SafeIndex/SafeEntList'),
              ),
            ),
          },
          {
            label: '企业安全指数详情',
            path: 'entIndexDetail',
            key: 'entIndexDetail',
            hidden: true,
            icon: <UserOutlined />,
            element: lazyLoadFn(
              lazy(
                () =>
                  import(
                    /* webpackChunkName: "safeIndexStatistics-dIndexDetail" */ '@/pages/boss/SafeIndex/SafeEntIndexDetail'
                  ),
              ),
            ),
          },
        ],
      },
    ],
  },
  {
    path: 'recruit',
    key: 'recruit',
    label: '招聘管理',
    icon: <VideoCameraOutlined />,
    element: <Outlet />,
    children: [
      {
        path: 'setBase',
        key: 'setBase',
        label: '基础设置',
        element: lazyLoadFn(
          lazy(() => import(/* webpackChunkName: "RecruitManage-SetBase" */ '@/pages/boss/RecruitManage/SetBase')),
        ),
      },
      {
        path: 'setResume',
        key: 'setResume',
        label: '简历设置',
        element: lazyLoadFn(
          lazy(() => import(/* webpackChunkName: "RecruitManage-SetBase" */ '@/pages/boss/RecruitManage/SetResume')),
        ),
      },
      {
        path: 'paymentLogs',
        key: 'paymentLogs',
        label: '收款记录',
        element: lazyLoadFn(
          lazy(() => import(/* webpackChunkName: "RecruitManage-SetBase" */ '@/pages/boss/RecruitManage/PaymentLogs')),
        ),
      },
      {
        path: 'signLogs',
        key: 'signLogs',
        label: '签字记录',
        element: lazyLoadFn(
          lazy(() => import(/* webpackChunkName: "RecruitManage-SetBase" */ '@/pages/boss/RecruitManage/SignLogs')),
        ),
      },
      {
        path: 'signDetail',
        key: 'signDetail',
        label: '签字记录详情',
        hidden: true,
        element: lazyLoadFn(
          lazy(() => import(/* webpackChunkName: "RecruitManage-SetBase" */ '@/pages/boss/RecruitManage/SignDetail')),
        ),
      },
      {
        path: 'phoneLogs',
        key: 'phoneLogs',
        label: '电话记录',
        element: lazyLoadFn(
          lazy(() => import(/* webpackChunkName: "RecruitManage-SetBase" */ '@/pages/boss/RecruitManage/PhoneLogs')),
        ),
      },
      {
        path: 'PhoneDetail',
        key: 'PhoneDetail',
        label: '电话记录详情',
        hidden: true,
        element: lazyLoadFn(
          lazy(() => import(/* webpackChunkName: "RecruitManage-SetBase" */ '@/pages/boss/RecruitManage/PhoneDetail')),
        ),
      },
    ],
  },
  {
    path: 'AiPlan',
    key: 'AiPlan',
    label: 'AI学习',
    icon: <VideoCameraOutlined />,
    element: lazyLoadFn(
      lazy(() => import(/* webpackChunkName: "resourceLibrary-courseware" */ '@/pages/boss/AiStudy/AiPlan')),
    ),
  },
  {
    path: 'aiStatic',
    key: 'aiStatic',
    label: 'AI学习统计',
    icon: <VideoCameraOutlined />,
    element: lazyLoadFn(lazy(() => import(/* webpackChunkName: "aiStatic-chart" */ '@/pages/boss/AiStudy/AiStatic'))),
  },
  {
    path: 'history',
    key: 'history',
    label: '计划学习情况',
    hidden: true,
    element: lazyLoadFn(
      lazy(() => import(/* webpackChunkName: "aiStatic-entPersonStudy" */ '@/pages/boss/AiStudy/AiStatic/History')),
    ),
  },
  {
    path: 'entPersonStudy',
    key: 'entPersonStudy',
    label: '计划学习情况',
    hidden: true,
    element: lazyLoadFn(
      lazy(
        () => import(/* webpackChunkName: "aiStatic-entPersonStudy" */ '@/pages/boss/AiStudy/AiStatic/EntPersonStudy'),
      ),
    ),
  },
];

const bossRoutes: bossRouteObject[] = [
  {
    path: '/',
    key: '/',
    element: <BossLayout />,
    errorElement: <ErrorBoundary />,
    children: bossRouterChildren,
  },
];

const bossRouter = createBrowserRouter(bossRoutes, {
  basename: process.env.processEnvDetail.REACT_APP_boss_browserRouterBaseName,
});

export { bossRouter, bossRouterChildren };
